﻿// The plane Physics Object create a level plane that can be positioned or
// rotated as needed. The Plane will NOT be affected by physics, save for
// external collisions upon its surface. IE, if something hits the plane,
// the physics for the colliding object will be calculated against the
// plane, however, the plane itself will not react. The plane is also not
// affected by gravity. This is the default building block of 3D worlds,
// use it for walls, floors, ceilings, etc, things that wont ever move.

using JigLibX.Collision;
using JigLibX.Physics;
using Microsoft.Xna.Framework;

namespace OmegaEngine
{
    // A flat plane physics object
    public class PlaneObject : PhysicsObject
    {
        // Constructors

        public PlaneObject()
            : base()
        {
            Setup();
        }

        public PlaneObject(Vector3 Position)
            : base()
        {
            Setup();
            this.Position = Position;
        }

        public PlaneObject(Vector3 Position, Vector3 Rotation)
            : base()
        {
            Setup();
            this.Position = Position;
            this.Rotation = MathUtil.Vector3ToMatrix(Rotation);
        }

        public PlaneObject(Vector3 Position, Matrix Rotation)
            : base()
        {
            Setup();
            this.Position = Position;
            this.Rotation = Rotation;
        }

        public PlaneObject(Vector3 Position, Vector3 Rotation, GameScreen Parent)
            : base(Parent)
        {
            Setup();
            this.Position = Position;
            this.Rotation = MathUtil.Vector3ToMatrix(Rotation);
            this.Parent = Parent;
        }

        public PlaneObject(Vector3 Position, Matrix Rotation, GameScreen Parent)
            : base(Parent)
        {
            Setup();
            this.Position = Position;
            this.Rotation = Rotation;
            this.Parent = Parent;
        }

        // Setup everything
        void Setup()
        {
            InitializeBody();
            //Body = new Body();
            //CollisionSkin = new CollisionSkin(Body);
            //Body.CollisionSkin = CollisionSkin;
            CollisionSkin.AddPrimitive(
                new JigLibX.Geometry.Plane(Vector3.Up, 0.0f),
                (int)MaterialTable.MaterialID.UserDefined,
                new MaterialProperties(0.8f, 0.8f, 0.7f));
            PhysicsSystem.CurrentPhysicsSystem.CollisionSystem.AddCollisionSkin(CollisionSkin);
            Body.SetInactive();
        }
    }
}
